package gatesvr

import (
	"lnzw/engine/define"
	"lnzw/engine/log"
	"lnzw/engine/net/tcp"
	"lnzw/server/logic/dispatcher"
)

const (
	USER_KEY define.ContextKeyId = "user_key"
)

type GateSocketHandle struct {
}

func (h *GateSocketHandle) OnConnect(client *tcp.SocketClient) {
	log.Logger.Info("gate client connected")
}

func (h *GateSocketHandle) OnMessage(client *tcp.SocketClient, data []byte) {
	dispatcher.DefaultDispatcher(client, data)
}

func (h *GateSocketHandle) OnClose(client *tcp.SocketClient) {
	controller := client.AttrValue("USER_KEY")
	if controller != nil {
		controller := controller.(*GateController)
		controller.OnClose()
	}
}
